package cn.uce.cc.srv.utils;

import cn.uce.base.ccos.DepartmentVo;
import cn.uce.base.vo.WaybillApplyVo;
import cn.uce.base.vo.WaybillInfoChangVo;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ScreenBusiWBPubApiConVer {


	/**
	 * @method network
	 * @param str_api
	 * @return
	 */
	public static Map converterQueryNetWork(String str_api) {
		Map<String, Object> map = new HashMap();
		if (!ScreenBusiConditionUtils.isEmptyForApi(str_api, "data")) {
			return map;
		}
		JSONObject jSONObject = JSONObject.parseObject(str_api);
		String str_api_temp = jSONObject.getString("data");
		DepartmentVo departmentVo = JSONObject.parseObject(str_api_temp, DepartmentVo.class);
		map.put("departmentVo", departmentVo);
		return map;
	}

    public static List<WaybillInfoChangVo> converterQueryWBChange(String str_api) {
        List<WaybillInfoChangVo> waybillInfoChangVo_list = new ArrayList();
        if (!ScreenBusiConditionUtils.isEmptyForApi(str_api, "data")) {
            return waybillInfoChangVo_list;
        }
        WaybillInfoChangVo waybillInfoChangVo = null;
        JSONObject jSONObject = JSONObject.parseObject(str_api);
        String str_api_temp = jSONObject.getString("data");
        List lst = JSONObject.parseArray(str_api_temp);
        for (Object obj : lst) {
            waybillInfoChangVo = new WaybillInfoChangVo();
            String waybillApplyVo_str = obj.toString();
            WaybillApplyVo waybillApplyVo = JSONObject.parseObject(waybillApplyVo_str, WaybillApplyVo.class);
            if (StringUtils.isNotEmpty(waybillApplyVo.getApplyContent())) {
                waybillInfoChangVo.setChangeContent(waybillApplyVo.getApplyContent());
            }
            if (StringUtils.isNotEmpty(waybillApplyVo.getCreater())) {
                waybillInfoChangVo.setChanger(waybillApplyVo.getCreater());
            }
            if (null != waybillApplyVo.getCreaterTime()) {
                waybillInfoChangVo
                        .setChangeTime(DateUtil.dateToString(waybillApplyVo.getCreaterTime(), "yyyy-MM-dd HH:mm"));
            }
            waybillInfoChangVo_list.add(waybillInfoChangVo);
        }
        return waybillInfoChangVo_list;
    }
}
